<?php 

/**
 * @package	Joomla.Tutorials
 * @subpackage	Module
 * @copyright	Copyright (C) 2005 - 2010 Open Source Matters, Inc. All rights reserved.
 * @license	License GNU General Public License version 2 or later; see LICENSE.txt
 */

// No direct access to this file
defined('_JEXEC') or die;

$com_path = JPATH_SITE . DS . 'components' . DS . 'com_product';

JModelLegacy::addIncludePath($com_path . DS . 'models', 'ProductModel');

class ProductCartHelper
{
	private $total;
	
	public function getCart() {
		$model = JModelLegacy::getInstance('Cart', 'ProductModel');
		$items = $model->getItems();
		$this->total = 0;
		if (isset($items)) {
			foreach ($items as &$item) {
				$item['link'] = JRoute::_('index.php?option=com_product&view=product&id=' . $item['id']);
				$item['thumbnail'] = JURI::root() . 'images/products/' . $item['data']->code . '/thumbnail.jpg';
				$item['deleteLink'] = JRoute::_('index.php?option=com_product&task=cart.delete&id=' . $item['id']);
				$item['price'] = $item['data']->discount > 0 ? $item['data']->discount : $item['data']->price;  
				$item['total'] = $item['price'] * $item['qty'];
				$this->total += $item['total'];
			}
		}
		return $items;
	}
	
	public function getTotal() {
		return $this->total;
	}
}
